<!--用户管理-->

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="/static/css/backstage/amazeui.min.css"  />
		<link rel="stylesheet" href="/static/css/backstage/admin.css"  />
		<link rel="stylesheet" href="/static/css/backstage/mobile_alert.css" >
		<style>
			.am-icon-sort{
				font-size: 12px;
				margin-left: 2px;
			}
			.sort:hover{
				color:#3b8cff;
				background:#f9f9f9;
			}
		</style>
	</head>
	#if(page>users.totalPages)
	<script>
		window.location.href="/backstage/user?key=${search}&page=${users.totalPages}&orderby=${orderby}";
	</script>
	#end
	<body>
		<div class="admin-content-body">
			<div class="am-cf am-padding am-padding-bottom-0">
				<div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户管理</strong><small></small></div>
			</div>

			<hr>

			<div class="am-g">
				<div class="am-u-sm-12 am-u-md-6">
					<div class="am-btn-toolbar">
						<div class="am-btn-group am-btn-group-xs">
							#if(search=="")
							<button type="button" class="am-btn am-btn-default addUser"><span class="am-icon-plus"></span> 新增</button>
							#else
							<button type="button" class="am-btn am-btn-default" onclick="location.href='/backstage/user'">
								<span class="am-icon-chevron-left"></span> 返回
							</button>
							#end
							<button type="button" style="display:none;" class="am-btn am-btn-default am-text-danger morecheck deleteMore"><span class="am-icon-trash-o"></span> 删除</button>
						</div>
					</div>
				</div>
				<div class="am-u-sm-12 am-u-md-3">

				</div>
				<div class="am-u-sm-12 am-u-md-3">
					<div class="am-input-group am-input-group-sm">
						<input type="text" style="color:blue;" placeholder="请输入姓名关键字" id="con" class="am-form-field" value="${search}">
						<span class="am-input-group-btn">
           					<button type="button" class="am-btn am-btn-default search" type="button">搜索</button>
          				</span>
					</div>
				</div>
			</div>
			<div class="am-g">
				<div class="am-u-sm-12">
					<form class="am-form">
						<input type="hidden" name="ids" id="ids">
						<table class="am-table am-table-striped am-table-hover table-main" style="text-align: center;">
							<thead>
								<tr>
									<th class="table-check"><input class="chooseall" type="checkbox"></th>
									<th class="table-id am-hide-sm-only sort" title="按ID排序"
										onclick="location.href='/backstage/user?key=${search}&page=${page}&orderby=m_id ${orderby=='m_id' ? 'desc':''} '">
										ID#if(orderby.indexOf("m_id")==0)<span class="am-icon-sort"></span>#end
									</th>
									<th class="table-title sort" title="按姓名排序"
										onclick="location.href='/backstage/user?key=${search}&page=${page}&orderby=convert(m_realname using gbk) ${orderby=='convert(m_realname using gbk)' ? 'desc':''}'">
										姓名#if(orderby.indexOf("convert(m_realname using gbk)")==0)<span class="am-icon-sort"></span>#end
									</th>
									<th class="table-type sort" title="按学号排序"
										onclick="location.href='/backstage/user?key=${search}&page=${page}&orderby=m_student_number ${orderby=='m_student_number' ? 'desc':''}'">
										学号#if(orderby.indexOf("m_student_number")==0)<span class="am-icon-sort"></span>#end
									</th>
									<th class="table-author am-hide-sm-only sort" title="按性别排序"
										onclick="location.href='/backstage/user?key=${search}&page=${page}&orderby=m_sex ${orderby=='m_sex' ? 'desc':''}'">
										性别#if(orderby.indexOf("m_sex")==0)<span class="am-icon-sort"></span>#end
									</th>
									<th class="table-author am-hide-sm-only sort" title="按组别排序"
										onclick="location.href='/backstage/user?key=${search}&page=${page}&orderby=m_group ${orderby=='m_group' ? 'desc':''}'">
										组别#if(orderby.indexOf("m_group")==0)<span class="am-icon-sort"></span>#end
									</th>
									<th class="table-set">操作</th>
								</tr>
							</thead>
							<tbody>
							#set(i = 0)
							#for(Users user : users.getRows())
								<tr>
									<td><input type="checkbox" name="checkbox" value="${user.m_id}"></td>
									<td class="am-hide-sm-only">${user.m_id}</td>
									<td>
										<a onclick="member(${user.m_id})">${user.m_realname}</a>
									</td>
									<td>${user.m_studentNumber}</td>
									#set(sex="未填")
									#if(user.m_sex==2)
									#set(sex="女")
									#end
									#if(user.m_sex==1)
									#set(sex="男")
									#end
									<td class="am-hide-sm-only">${sex}</td>
									#if (user.m_group!=null)
									<td class="am-hide-sm-only">${groups[i].g_gname}</td>
									#else
									<td class="am-hide-sm-only">未填</td>
									#end
									<td>
										<div class="am-btn-toolbar">
											<div class="am-btn-group am-btn-group-xs">
												<button type="button" onclick="editUser(${user.m_id})" class="am-btn am-btn-default am-btn-xs am-text-secondary editUser"><span class="am-icon-pencil-square-o"></span> 编辑</button>
												<button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only deleteThis"><span class="am-icon-trash-o"></span> 删除</button>
											</div>
										</div>
									</td>
								</tr>
							#set(i=i+1)
							#end

							#if(i==0)
							<tr><td class="am-hide-sm-only"></td><td></td><td></td><td></td><td>暂无记录！</td><td></td><td class="am-hide-sm-only"></td></tr>
							#end
							</tbody>
						</table>
						<div class="am-cf">
							共 ${users.getTotalRows()} 条记录
							#if(search!="")(查询结果）
							#end
							<div class="am-fr">
								<ul class="am-pagination">
									<li class="${users.isHasPrevPage()  ? '':'am-disabled'}">
										<a href="/backstage/user?key=${search}&page=${users.getPrevPage()}&orderby=${orderby}">«</a>
									</li>
									#set(j=users.getPageNum()-(users.getPageNum()%5!=0?users.getPageNum()%5:5)+1)
									#for(i : range(j, (j+4) > users.totalPages ? users.totalPages : j+4))
									<li class="${i == users.pageNum  ? 'am-active':''}">
										<a href="/backstage/user?key=${search}&page=${i}&orderby=${orderby}">${i}</a>
									</li>
									#end
									<li class="${users.isHasNextPage()  ? '':'am-disabled'}">
										<a href="/backstage/user?key=${search}&page=${users.getNextPage()}&orderby=${orderby}">»</a>
									</li>
								</ul>
							</div>
						</div>
						<hr>
					</form>
				</div>
			</div>
		</div>
		#include('/backstage/footer.html')
		<script type="text/javascript" src="/static/js/backstage/jquery-1.8.3.js"></script>
		<script type="text/javascript" src="/static/js/backstage/plugs.js" ></script>
		<script type="text/javascript" src="/static/js/backstage/choose.js" ></script>
		<script>

			function check(){
				var checkID = [];//定义一个空数组
				$("input[name='checkbox']:checked").each(function(j){//把所有被选中的复选框的值存入数组
					 checkID[j] =$(this).val();
				});
				$("#ids").val(checkID);
			}

			function editUser(id) {

					$.jq_Panel({
						title: "编辑资料",
						iframeWidth: 500,
						iframeHeight: 360,
						url: "editUser/"+id
					});
			}

			function member(id){
					window.parent.$.jq_Panel({
						title: "用户信息",
						iframeWidth: 700,
						iframeHeight: 500,
						url: "/users/"+id
					});
			}

        	$(function() {

        	    $(".search").click(function(){
			        window.location.href="/backstage/user?key="+$("#con").val()+"&orderby=${orderby}";
			    });

				$(".addUser").click(function() {

					$.jq_Panel({
						title: "添加用户",
						iframeWidth: 500,
						iframeHeight: 360,
						url: "addUser"
					});
				});

				$(".deleteThis").click(function() {
					if(confirm('确定删除该用户吗？')){
						$("#ids").val($(this).parents("tr").find("input[name='checkbox']").val());
			        	$.ajax({
							url:"/backstage/user_delete",
							dataType:"json",
							type:"post",
							data:$("form").serialize(),
							success:function(result){
								alert("删除成功！");
								window.location.href=location.href;
							},
							error:function(result){
              				  	alert("系统繁忙！");
           					 }
						});
						<!--$(this).parents("tr").remove();-->
					}
				});
				$(".deleteMore").click(function() {
						if(confirm('确定批量删除用户吗？')){
							check();
							$.ajax({
								url:"/backstage/user_delete",
								dataType:"json",
								type:"post",
								data:$("form").serialize(),
								success:function(result){
									alert(result.tips+"名用户删除成功！");
									window.location.href=location.href;
								},
								error:function(result){
									alert("系统繁忙！");
								 }
							});
							<!--$('tbody input[type=checkbox]:checked').parents("tr").remove();-->
							<!--$("thead input[type='checkbox']").prop("checked", true).click();-->
						}
				});
			});
		</script>
	</body>
</html>